package org.wisteria.framework.web;

/**
 * 系统业务处理异常类
 * @author Lei.Liu
 *
 */
public class BusinessException extends RuntimeException {
	private static final long serialVersionUID = 1720283557480368402L;

	protected String errorCode;

    protected String[] errorMessageArgs = new String[0];

	public BusinessException() {
        super("");
    }
    
    public BusinessException(String message) {
	    super(message);
	    this.errorCode = "fail";
    }
    
    public BusinessException(String message, Throwable cause) {
        super(message, cause);
        this.errorCode = "fail";
    }

    public static BusinessException withErrorCode(String errorCode) {
        BusinessException businessException = new BusinessException();
        businessException.errorCode = errorCode;
        return businessException;
    }

    public static BusinessException withFail(String errorCode, String message) {
        BusinessException businessException = new BusinessException(message);
        businessException.errorCode = errorCode;
        return businessException;
    }

    public static BusinessException withMessage(String message) {
        return new BusinessException(message);
    }

    public BusinessException withErrorMessageArgs(String... errorMessageArgs) {
        if (errorMessageArgs != null) {
            this.errorMessageArgs = errorMessageArgs;
        }
        return this;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String[] getErrorMessageArgs() {
        return errorMessageArgs;
    }

    public void setErrorMessageArgs(String[] errorMessageArgs) {
        this.errorMessageArgs = errorMessageArgs;
    }
}
